View on GitHub

csc263

Notes for CSC263 - Data Structures and Analysis

Back to index

Mergable Priority Queues

Operations

Binomial Trees

$B_k$ Trees defined recursively:

  1. image-20200113154011982
  2. image-20200113154031726
  3. image-20200113154045009

In general, create $B_{n+1}$ tree by taking two $B_n$ trees, $A$ and $B$ and making the root of $B$ the first child of the root of $A$

Properties of $B_k$

Binomial Forest of size $n$ ($F_n$)

A sequence of $B_k$ trees with $k$ strictly decreasing with $n$ total nodes

Min Binomial Heap

A min binomial heap is a binomial forest where:

Implementation

Storage

Merging min binomial heaps of same size $P_k$ and $Q_k$

Union of min binomial forests (union(A, B))

(works exactly like algorithm for addition of binary numbers)

  1. start at smallest $B_k$ tree in both
  2. if tree is only in one forest (or is carry), then keep as-is in the union forest
  3. if there are $B_k$ trees with same size in both, merge them to get a $B_{k+1}$ tree
  4. carry the new $B_{k+1}$ tree, repeat from step 2

for $\vert A \vert \leq n$ and $\vert B \vert \leq n$, the complexity of union(A, B) is $\mathcal O(\log(n))$

insert(A, x)

Make a new binomial forest with a single $B_0$ tree which stores x, then “add” it to A

def insert(A, x):
    b = new B_0 Tree
    b.insert(x)
    B = new BinomialHeap(b)
    A = union(A, B)

decrease_key(A, x, k)